package com.lan.parse;


import com.lan.model.symbol.Scope;
import com.lan.model.symbol.Variable;

import java.util.Stack;

public class StackSymbol {

    private SymbolTree symbolTree;

    private Stack<SymbolTree> stack;

    public StackSymbol() {
        this.stack = new Stack<>();
    }


    public String getNowId() {
        return symbolTree.getScope().getId();
    }

    public Scope getScope() {
        return symbolTree.getScope();
    }


    public Variable getVariable(String id) {

        return null;
    }

    public void setContext(SymbolTree context) {
        this.symbolTree = context;
    }

    public Stack<SymbolTree> getStack() {
        return stack;
    }

    public void setStack(Stack<SymbolTree> stack) {
        this.stack = stack;
    }

    public void pushScope(SymbolTree symbolTree) {
        if (stack.size() > 0) {
            SymbolTree scope = stack.get(stack.size() - 1);
            scope.put(symbolTree.getScope());
        }
        this.symbolTree = symbolTree;
        this.stack.push(symbolTree);
    }

    public void push(SymbolTree context) {
        if (stack.size() > 0) {
            SymbolTree scope = stack.get(stack.size() - 1);
            scope.put(context.getScope());
        }
        this.symbolTree = context;
    }

    public SymbolTree get() {
        return this.symbolTree;
    }


    public void pop() {
        stack.pop();
        this.symbolTree = stack.peek();
    }
}
